package com.youlai.boot.weekPlan.controller;

import com.youlai.boot.weekPlan.service.UserWeekPlanService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.youlai.boot.weekPlan.model.form.UserWeekPlanForm;
import com.youlai.boot.weekPlan.model.query.UserWeekPlanQuery;
import com.youlai.boot.weekPlan.model.vo.UserWeekPlanVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.youlai.boot.common.result.PageResult;
import com.youlai.boot.common.result.Result;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;

/**
 * 用户每周运动时常计划前端控制层
 *
 * @author cuisheng
 * @since 2025-04-01 10:39
 */
@Tag(name = "用户每周运动时常计划接口")
@RestController
@RequestMapping("/api/v1/userWeekPlans")
@RequiredArgsConstructor
public class UserWeekPlanController  {

    private final UserWeekPlanService userWeekPlanService;

    @Operation(summary = "用户每周运动时常计划分页列表")
    @GetMapping("/page")
    public PageResult<UserWeekPlanVO> getUserWeekPlanPage(UserWeekPlanQuery queryParams ) {
        IPage<UserWeekPlanVO> result = userWeekPlanService.getUserWeekPlanPage(queryParams);
        return PageResult.success(result);
    }

    @Operation(summary = "新增用户每周运动时常计划")
    @PostMapping
    public Result<Void> saveUserWeekPlan(@RequestBody @Valid UserWeekPlanForm formData ) {
        boolean result = userWeekPlanService.saveUserWeekPlan(formData);
        return Result.judge(result);
    }

    @Operation(summary = "获取用户每周运动时常计划表单数据")
    @GetMapping("/form")
    public Result<UserWeekPlanForm> getUserWeekPlanForm(
    ) {
        UserWeekPlanForm formData = userWeekPlanService.getUserWeekPlanFormData();
        return Result.success(formData);
    }

    @Operation(summary = "修改用户每周运动时常计划")
    @PutMapping(value = "/{id}")
    public Result<Void> updateUserWeekPlan(
            @Parameter(description = "用户每周运动时常计划ID") @PathVariable Long id,
            @RequestBody @Validated UserWeekPlanForm formData
    ) {
        boolean result = userWeekPlanService.updateUserWeekPlan(id, formData);
        return Result.judge(result);
    }

    @Operation(summary = "删除用户每周运动时常计划")
    @DeleteMapping("/{ids}")
    public Result<Void> deleteUserWeekPlans(
        @Parameter(description = "用户每周运动时常计划ID，多个以英文逗号(,)分割") @PathVariable String ids
    ) {
        boolean result = userWeekPlanService.deleteUserWeekPlans(ids);
        return Result.judge(result);
    }
}
